
#include <iostream>
using namespace std;


template<typename X> class A {
public:
	void foo( ) {
		cout << "A<X>::foo( )" << endl;
	}
	template<typename Y> class B{
	public:
		template<typename T> void func(){
			cout << "A<X>::B<Y>::func<T>()" << endl;
		}
		template<typename Z> class C;
	};
};

template<typename X>
template<typename Y>
template<typename Z>class A<X>::B<Y>::C{
public:
	void bar(){
		cout << "A<X>::B<Y>::C<Z>::bar()" << endl;
	}
	template<typename D>void func2() {
		cout << "A<X>::B<Y>::C<Z>::func2<D>()" << endl;
	}
};

int main() {
	A<int> a;
	a.foo();

	A<int>::B<double> b;
	b.func<string>();

	A<short>::B<int>::C<double> c;
	c.bar();
	c.func2<float>();

	return 0;
}
